// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   PIVL_TSImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.common.Hl7Exception;
import com.sunwayhorizo.health.hl7.common.VersionInfo;
import com.sunwayhorizo.health.hl7.datatypes.ANY;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.INT;
import com.sunwayhorizo.health.hl7.datatypes.IVL_TS;
import com.sunwayhorizo.health.hl7.datatypes.PIVL;
import com.sunwayhorizo.health.hl7.datatypes.PQ;
import com.sunwayhorizo.health.hl7.datatypes.ST;
import com.sunwayhorizo.health.hl7.datatypes.TYPE;
import com.sunwayhorizo.health.hl7.datatypes.common.gtsparser.TimeParser;

import java.io.StringReader;


// Referenced classes of package oracle.apps.ctb.hl7.types.common:
//            GTSBase, ANYImpl, BLImpl, CSImpl, 
//            IVL_TSImpl, NullFlavorImpl, PQImpl, STImpl, 
//            TYPEImpl

public class PIVL_TSImpl extends GTSBase
    implements PIVL
{

    public static final String RCS_ID = "$Header: PIVL_TSImpl.java 115.26.2050.2 2005/10/11 01:22:10 mmoores noship $";
    public static final boolean RCS_ID_RECORDED = VersionInfo.recordClassVersion("$Header: PIVL_TSImpl.java 115.26.2050.2 2005/10/11 01:22:10 mmoores noship $", "oracle.apps.ctb.hl7.types.common");
    protected IVL_TS _phase;
    protected PQ _period;
    protected CS _alignment;
    protected BL _institutionSpecifiedTime;

    public static PIVL nullPIVL_TS(CS cs)
    {
        return new PIVL_TSImpl(cs);
    }

    public static PIVL valueOf(IVL_TS ivl_ts, PQ pq, CS cs, BL bl)
    {
        return new PIVL_TSImpl(ivl_ts, pq, cs, bl);
    }

    public static PIVL valueOf(CS cs, ST st, INT int1, BL bl)
    {
        throw ANYImpl.newUnsupportedException("PIVL<TS>", "valueOf");
    }

    public static PIVL valueOf(CS cs, ST st, ST st1, INT int1, BL bl)
    {
        throw ANYImpl.newUnsupportedException("PIVL<TS>", "valueOf");
    }

    public static PIVL valueOf(String s)
        throws Hl7Exception
    {
        StringReader stringreader = new StringReader(s);
        TimeParser timeparser = new TimeParser(stringreader);
        try
        {
            PIVL pivl = timeparser.pivl();
            GTSBase.checkParserState(timeparser);
            ((GTSBase)pivl)._literal = STImpl.valueOf(s);
            ((GTSBase)pivl)._dataType = com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.PIVL;
            return pivl;
        }
        catch(Throwable throwable)
        {
            throw ANYImpl.newParseException("PIVL", s, throwable);
        }
    }

    protected PIVL_TSImpl(IVL_TS ivl_ts, PQ pq, CS cs, BL bl)
    {
        if(pq == null || pq.isNull().isTrue())
        {
            if(ivl_ts == null || ivl_ts.isNull().isTrue())
                throw ANYImpl.newNullException("PIVL<TS>", "constructor", "phase");
            if(pq == null || pq.isNull().isTrue())
                throw ANYImpl.newNullException("PIVL<TS>", "constructor", "period");
        }
        _phase = ivl_ts;
        _period = pq;
        _alignment = cs;
        _institutionSpecifiedTime = bl;
        _dataType = com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.PIVL;
    }

    protected PIVL_TSImpl()
    {
        _dataType = com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.PIVL;
    }

    protected PIVL_TSImpl(CS cs)
    {
        super(cs);
        _phase = IVL_TSImpl.nullIVL_TS(cs);
        _period = PQImpl.nullPQ(cs);
        _alignment = CSImpl.nullCS(cs);
        _institutionSpecifiedTime = BLImpl.nullBL(cs);
        _dataType = com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.PIVL;
    }

    protected String generateLiteral()
    {
        StringBuffer stringbuffer = new StringBuffer();
        if(phase().isNull().isFalse())
            stringbuffer.append(phase().literal().stringValue());
        stringbuffer.append("/(");
        stringbuffer.append(period().literal().stringValue());
        stringbuffer.append(")");
        if(alignment().isNull().isFalse())
        {
            stringbuffer.append("@");
            stringbuffer.append(alignment().literal().stringValue());
        }
        if(institutionSpecifiedTime().isTrue())
            stringbuffer.append(" IST");
        return stringbuffer.toString();
    }

    public TYPE dataType()
    {
        return _dataType;
    }

    public BL equal(ANY any)
    {
        if(!(any instanceof PIVL))
            return BLImpl.FALSE;
        if(isNull().or(any.isNull()).isTrue())
        {
            return BLImpl.FALSE;
        } else
        {
            PIVL pivl = (PIVL)any;
            return phase().equal(pivl.phase()).or(phase().isNull().and(pivl.phase().isNull())).and(period().equal(pivl.period())).and(alignment().equal(pivl.alignment()).or(alignment().isNull().and(pivl.alignment().isNull()))).and(institutionSpecifiedTime().equal(pivl.institutionSpecifiedTime()).or(institutionSpecifiedTime().isNull().and(pivl.institutionSpecifiedTime().isNull())));
        }
    }

    public IVL_TS phase()
    {
        return _phase;
    }

    public PQ period()
    {
        return _period;
    }

    public CS alignment()
    {
        return _alignment;
    }

    public BL institutionSpecifiedTime()
    {
        return _institutionSpecifiedTime;
    }

    public IVL_TS hull()
    {
        return IVL_TSImpl.nullIVL_TS(NullFlavorImpl.NA);
    }

//    public XMLNode[] writeXML(XMLDocument xmldocument, String s)
//        throws Hl7Exception
//    {
//        try
//        {
//            XMLElement xmlelement = null;
//            if(period() != null && period().isNull().isFalse())
//            {
//                xmlelement = (XMLElement)xmldocument.createElement(s);
//                xmlelement.appendChild(((PQImpl)period()).writeXML(xmldocument, "period")[0]);
//            }
//            if(phase() != null && phase().isNull().isFalse())
//                xmlelement.appendChild(((IVL_TSImpl)phase()).writeXML(xmldocument, "phase")[0]);
//            if(alignment() != null && alignment().isNull().isFalse())
//                xmlelement.setAttribute("alignment", alignment().code().stringValue());
//            if(institutionSpecifiedTime() != null)
//                xmlelement.setAttribute("institutionSpecified", institutionSpecifiedTime().isTrue() ? "true" : "false");
//            return (new XMLNode[] {
//                xmlelement
//            });
//        }
//        catch(Exception exception)
//        {
//            throw new Hl7Exception(exception);
//        }
//    }

}
